dofile("StylusBox2.lua")
dofile("libColor.lua")

Button = {
	new = function (scr, x, y, w, h, txt)
		local x2 = x + w
		local y2 = y + h
		
		local txtx = (x+w/2)-((string.len (txt)*6)/2)
		local txty = (y+h/2)-(9/2)
		
		local c1 = c_wingrey
		local c2 = c_black
		
		local draw = function (self)
			screen.drawRect (scr, x, y, x2, y2, c_grey)
			screen.drawRect (scr, x+1, y+1, x2-1, y2-1, c1)
			screen.drawLine (scr, x+2, y2-2, x2-1, y2-2, c2)
			screen.drawLine (scr, x2-2, y+2, x2-2, y2-2, c2)
			screen.drawFillRect (scr, x+2, y+2, x2-2, y2-2, c_grey)
			screen.print (scr, txtx, txty, txt, c_black)
			
			if StylusBox.simpleHold (x, y, x2, y2, Stylus.X, Stylus.Y) then
			  c1 = c_black
			  c2 = c_wingrey
			else 
			  c1 = c_wingrey
			  c2 = c_black
			end
		 end
		 
		 local clicked = function (self)
			local clicked = false
			
			if StylusBox.simplePressed (x, y, x2, y2, Stylus.X, Stylus.Y) then
			  clicked = true
			end
			
			return clicked
		end
		
		local setPositions = function (self, xx, yy, ww, hh)
			x, y, w, h = xx, yy, ww, hh
			x2 = x+w
			y2 = y+h
		end
		
		local setText = function (self, text)
			txt = text
		end
		
		local setColors = function (self, cc1, cc2)
			c1, c2 = cc1, cc2
			assert(c1 ~= nil, "Please set a Color value to c1")
			assert(c2 ~= nil, "Please set a Color value to c2")
		end
		
		local clear = function (self)
			self = nil
		end
		
		return{
			-- Functions --
			draw = draw,
			clicked = clicked,
			clear = clear,
			-- Variables --
			screen = scr,
			x = x,
			y = y,
			w = w,
			h = h,
			x2 = x2,
			y2 = y2,
			text = txt,
			c1 = c1,
			c2 = c2,
			-- Other --
			setPositions = setPositions,
			setText = setText,
			setColors = setColors
		}
	end
}
